
let express = require("express")    // require相当于import(导入)

// 导入模块
let user = require('./modules/user')
let msbd = require('./modules/msbd')
let classify = require('./modules/classify')
let permission = require('./modules/permission')
let detail = require('./modules/detail')
let test = require('./modules/test')

let app = express() //调用方法，获取实例

// 解决跨域问题
app.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Headers', 'X-Requested-With, content-type, x-token, x-access-token');
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS,PATCH");
    // res.header('Access-Control-Max-Age', 1728000);//预请求缓存20天
    res.header('Content-Type', 'application/json;charset=utf-8') // 内容格式
    next();
});

// 设置模块路径
app.use('/user', user)
app.use('/msbd', msbd)
app.use('/classify', classify)
app.use('/permission', permission)
app.use('/detail', detail)
app.use('/test', test)

let server = app.listen(2000, function () {
    let host = server.address().address
    let port = server.address().port
    console.log("应用实例，访问地址为 http://%s:%s", host, port)
})